/**
 * @(#) BasicViewInfoProxy.as
 *
 * @date		2009. 02. 12.
 * @version		1.0
 * @author		Shin, Yunwoo
 * @description	 연말정산 - Proxy
 * 				기본 데이터 조회 Model Logic 
 */
package com.skt.common_hr.yearadjustment.model
{
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.yearadjustment.YearAdjustmentFacade;
	import com.skt.common_hr.yearadjustment.model.vo.AdditionSubtractionCntVO;
	import com.skt.common_hr.yearadjustment.model.vo.AmountReductionMoneyVO;
	import com.skt.common_hr.yearadjustment.model.vo.AnnuitySubtractionMoneyVO;
	import com.skt.common_hr.yearadjustment.model.vo.BasicSubtractionCntVO;
	import com.skt.common_hr.yearadjustment.model.vo.DonationSubtractionMoneyVO;
	import com.skt.common_hr.yearadjustment.model.vo.EducationalSubtractionMoneyVO;
	import com.skt.common_hr.yearadjustment.model.vo.HouseFundSubtractionMoneyVO;
	import com.skt.common_hr.yearadjustment.model.vo.MarriageSubtractionCntVO;
	import com.skt.common_hr.yearadjustment.model.vo.MedicalSubtractionMoneyVO;
	import com.skt.common_hr.yearadjustment.model.vo.ModifyMsgVO;
	import com.skt.common_hr.yearadjustment.model.vo.OtherSubtractionMoneyVO;
	import com.skt.common_hr.yearadjustment.model.vo.PremiumSubtractionMoneyVO;
	import com.skt.common_hr.yearadjustment.model.vo.TotalIncomeMoneyVO;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	

	public class BasicViewInfoProxy extends CommonProxy
	{
		public static const NAME:String = "BasicViewInfoProxy";
		
		public var modifyMsg:ArrayCollection;				//탭1 개요 수정 항목
		public var totalincomeVo:TotalIncomeMoneyVO;			//탭2 총소득액
		public var basicsubtractionVo:BasicSubtractionCntVO;	//탭3 인적기본공제
		public var additionVo:AdditionSubtractionCntVO;			//탭4 인적추가공제
		public var annuityVo:AnnuitySubtractionMoneyVO;			//탭5 연금보혐료공제
		public var premiumVo:PremiumSubtractionMoneyVO;			//탭6 보험료공제
		public var medicalVo:MedicalSubtractionMoneyVO;			//탭7 의료비공제
		public var educationalData:ArrayCollection;				//탭8 교육비공제
		public var houseFundVo:HouseFundSubtractionMoneyVO;		//탭9 주택자금공제
		public var donationVo:DonationSubtractionMoneyVO;		//탭10 기부금공제
		public var marriageVo:MarriageSubtractionCntVO;			//탭11 혼인,장례,이사비공제
		public var otherSubtractionVo:OtherSubtractionMoneyVO;	//탭12 기타소득공제
		public var amountReductionVo:AmountReductionMoneyVO;	//탭13 세액감면 및 세액공제


		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function BasicViewInfoProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번
		 * @return void
		 */
		public function load(pernr:String, year:String):void
		{
			var param:Object = new Object();
			param["I_YEAR"] = year;
			param["I_PERNR"] = pernr;
			loadData("Z_HR_0082_NEW", param, result, fault); 
		}
		
		
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			if(retCode==0) {  
				trace( "suss to load BasicViewInfoProxy");
				totalincomeVo = preseTotalincome(event.result.ITAB1[0]);
				basicsubtractionVo = preseBasicsubtraction(event.result.ITAB2[0]);
				additionVo = preseAddition(event.result.ITAB3[0]);
				annuityVo = preseAnnuity(event.result.ITAB4[0]);
				premiumVo = presePremium(event.result.ITAB5[0]);
				medicalVo = preseMedical(event.result.ITAB6[0], event.result.ITAB1[0]);
				educationalData = preseEdu(event.result.ITAB7);
				houseFundVo = preseHouseFund(event.result.ITAB8[0]);
				donationVo = preseDonation(event.result.ITAB9[0]);
				marriageVo = preseMarriage(event.result.ITAB10[0]);
				otherSubtractionVo = preseOther(event.result.ITAB11[0]);
				amountReductionVo = preseAmountReduction(event.result.ITAB12[0]);
				modifyMsg = preseModifyMsg(event.result.ITAB13);
				facade.sendNotification(YearAdjustmentFacade.LOAD_BASICINFO_COMPLETE, this);
			}
			else {
				trace( "failed to load BasicViewInfoProxy: (" +event.result["RETCODE"] + ") "+event.result["RETTEXT"]);
				facade.sendNotification(YearAdjustmentFacade.LOAD_BASICINFO_FAILED, this);
			}
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			trace("Fault message in BasicViewInfoProxy: " + event.fault.faultString);
			facade.sendNotification(YearAdjustmentFacade.LOAD_BASICINFO_FAILED, this);
		}
		
		
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 연말정산  MainList Value Object
		 */
		/* private function parseMainList(arr:ArrayCollection):ArrayCollection
		{
			var returnArr:ArrayCollection = new ArrayCollection();
			for each(var reg:Object in arr){
				var vo:YearAdjustmentVO = new YearAdjustmentVO();
				vo.YEAR		= reg["YEAR"];
				vo.PERNR	= StringUtil.trimFront(reg["PERNR"], "0");
				vo.ENAME	= reg["ENAME"];
				vo.ORGTX	= reg["ORGTX"];
				vo.TAXPAY	= reg["TAXPAY"];
				vo.PRETAX	= reg["PRETAX"];
				vo.FIXTAX	= reg["FIXTAX"];
				vo.MINTAX	= reg["MINTAX"];
				
				returnArr.addItem(vo);
			}
			return returnArr;
		} */
		
		
		//총소득액
		private function preseTotalincome(retObj:Object):TotalIncomeMoneyVO{
			var vo:TotalIncomeMoneyVO = new TotalIncomeMoneyVO();
			
			vo.SALTOT	= retObj["SALTOT"];
			vo.BOUTOT	= retObj["BOUTOT"];
			vo.RECTOT	= retObj["RECTOT"];
			vo.PRETAX	= retObj["PRETAX"];
			vo.EXPTAX	= retObj["EXPTAX"];
			vo.FXPTAX	= retObj["FXPTAX"];
			vo.OXPTAX	= retObj["OXPTAX"];
			
			return vo;
		}
		//인적기본공제
		private function preseBasicsubtraction(retObj:Object):BasicSubtractionCntVO{
			var vo:BasicSubtractionCntVO = new BasicSubtractionCntVO();
			
			vo.SPOU		= retObj["SPOU"];		//배우자 공제
			vo.DEPSUM 	= retObj["DEPSUM"];		//부양가족 공제 합
			vo.DEPGR 	= retObj["DEPGR"];		//직계존속
			vo.DEPCH 	= retObj["DEPCH"];		//직계비속(자녀)
			vo.DEPCX 	= retObj["DEPCX"];		//직계비속(자녀외) 2008
			vo.DEPBS 	= retObj["DEPBS"];		//형제자매
			vo.DEPEX 	= retObj["DEPEX"];		//기타 2008
			vo.DEPSG 	= retObj["DEPSG"];		// 수급자
			vo.DEPAD 	= retObj["DEPAD"];		/// 위탁아동
			/*
			vo.SPOU		= retObj["SPOU"];
			vo.DEPSUM	= retObj["DEPSUM"];
			vo.DEPGR	= retObj["DEPGR"];
			vo.DEPCH	= retObj["DEPCH"];
			vo.DEPCX	= retObj["DEPCX"];
			vo.DEPBS	= retObj["DEPBS"];
			vo.DEPEX	= retObj["DEPEX"];
			*/
			
			return vo;
		}
		//인적추가공제
		private function preseAddition(retObj:Object):AdditionSubtractionCntVO{
			var vo:AdditionSubtractionCntVO = new AdditionSubtractionCntVO();
			
			vo.OLD01	= retObj["OLD01"];
		 	vo.OLD02	= retObj["OLD02"];
		 	vo.HNDID	= retObj["HNDID"];
		 	vo.HUSID	= retObj["HUSID"];
		 	vo.CHDID	= retObj["CHDID"];
		 	vo.MUCHD	= retObj["MUCHD"];
		 	vo.ADCID	= retObj["ADCID"];
		 	vo.SIGPR	= retObj["SIGPR"];
		 	
			vo.CHNUM = retObj["CHNUM"]; // 2014
			return vo;
		}
		//연금보험료 공제
		private function preseAnnuity(retObj:Object):AnnuitySubtractionMoneyVO{
			var vo:AnnuitySubtractionMoneyVO = new AnnuitySubtractionMoneyVO();
			
			vo.PEAMT	= retObj["PEAMT"];
			vo.RETPE	= retObj["RETPE"];
			return vo;
		}
		//특별공제 보험료
		private function presePremium(retObj:Object):PremiumSubtractionMoneyVO{
			var vo:PremiumSubtractionMoneyVO = new PremiumSubtractionMoneyVO();
			
			vo.MEAMT	= retObj["MEAMT"];
			vo.UEAMT	= retObj["UEAMT"];
			vo.GEAMT	= retObj["GEAMT"];
			vo.HDAMT	= retObj["HDAMT"];
			return vo;
		}
		//특별공제  의료비
		private function preseMedical(retObj:Object, totalObj:Object):MedicalSubtractionMoneyVO{
			var vo:MedicalSubtractionMoneyVO = new MedicalSubtractionMoneyVO();
			//2013
			vo.HDAMT	= retObj["HDAMT"];
			vo.SMAMT	= retObj["SMAMT"];
			vo.EMAMT	= retObj["EMAMT"];
			vo.METOT	= retObj["METOT"];
			vo.TOAMT	= retObj["TOAMT"];
			vo.PCNT3	= totalObj["3PCNT"];
			return vo;
		}
		//특별공제  교육비 공제
		private function preseEdu(arr:ArrayCollection):ArrayCollection{
			var returnArr:ArrayCollection = new ArrayCollection();
			for each(var reg:Object in arr){
				var vo:EducationalSubtractionMoneyVO = new EducationalSubtractionMoneyVO();
				vo.SEQNO	= int(reg["SEQNO"]).toString();
				trace("seq  " + int(reg["SEQNO"]).toString());
				vo.YEASUB	= reg["YEASUB"];
				vo.YEASUBTX	= reg["YEASUBTX"];
				vo.AMT		= reg["AMT"];
				returnArr.addItem(vo);
			}
			return returnArr;
		}
		//특별공제  주택자금 공제
		private function preseHouseFund(retObj:Object):HouseFundSubtractionMoneyVO{
			var vo:HouseFundSubtractionMoneyVO = new HouseFundSubtractionMoneyVO();

			vo.REPAY	= retObj["REPAY"];		//원리금 상환 공제
			vo.INDPL	= retObj["INDPL"];		//개인 차입금상환액
			vo.MRNTD	= retObj["MRNTD"];		//월세액총액

			vo.FPRDO	= retObj["FPRDO"];		//주택이자(600)
			vo.INTTL	= retObj["INTTL"];		//주택이자(1000)
//shgoo 2010.01.07
			//1500만원 한도
			vo.INSLN	= retObj["INSLN"];		//주택이자(1500)
/////////////////

//shgoo 2010.01.11
			vo.HSSAV 	= retObj["HSSAV"];	//주택마련저축
			vo.EEHSS 	= retObj["EEHSS"];	//근로자주택마련저축
			vo.LHSSV 	= retObj["LHSSV"];	//장기주택바련저축
			vo.HSHLD 	= retObj["HSHLD"];	//세대주 여부
///////////////////

//j.t 2012.12.28
			vo.INTFN 	= retObj["INTFN"];	//고정금리/비거치대출
			vo.INTOT 	= retObj["INTOT"];	//기타대출-500만원
			vo.BETRG 	= retObj["BETRG"];	//총소득액
			vo.LIMIT 	= retObj["LIMIT"];	//총급여상한선
///////////////////

//2014
			vo.LIMIT_M 	= retObj["LIMIT_M"];	//총급여상한선
			return vo;
		}
		//특별공제  기부금
		private function preseDonation(retObj:Object):DonationSubtractionMoneyVO{
			var vo:DonationSubtractionMoneyVO = new DonationSubtractionMoneyVO();
			
			vo.FLG01	= retObj["FLG01"];
			vo.POLDN	= retObj["POLDN"];
			vo.FLG02	= retObj["FLG02"];
			vo.SPCDO	= retObj["SPCDO"];
			vo.DESDO	= retObj["DESDO"];
			vo.RELDO	= retObj["RELDO"];
			
			vo.D10		= retObj["D10"];	//법정기부금
			vo.D20		= retObj["D20"];	//정치자금기부금
			vo.D30		= retObj["D30"];	//특례기부금
			vo.D31		= retObj["D31"];	//공익법인기부신탁기부금
			vo.D40		= retObj["D40"];	//종교단체외 지정기부금
			vo.D41		= retObj["D41"];	//종교단체기부금
			vo.D42		= retObj["D42"];	//우리사주조함기부금
			return vo;
		}
		//특별공제 혼인,장례,이사비
		private function preseMarriage(retObj:Object):MarriageSubtractionCntVO{
			var vo:MarriageSubtractionCntVO = new MarriageSubtractionCntVO();
			
			vo.CONMA	= retObj["CONMA"];
			vo.CONFU	= retObj["CONFU"];
			vo.CONRE	= retObj["CONRE"];
			
			return vo;
		}
		
		//기타소득공제
		private function preseOther(retObj:Object):OtherSubtractionMoneyVO{
			var vo:OtherSubtractionMoneyVO = new OtherSubtractionMoneyVO();
			
			vo.FPERP	= retObj["FPERP"];
			vo.FPERN	= retObj["FPERN"];
			vo.HSSAV	= retObj["HSSAV"];
//shgoo 2010.01.06
			vo.EEHSS	= retObj["EEHSS"];
			vo.LHSSV	= retObj["LHSSV"];
			vo.MTHSS	= retObj["MTHSS"];
////////////////
			vo.CDAMT	= retObj["CDAMT"];
			vo.CAAMT	= retObj["CAAMT"];
			vo.SCAMT	= retObj["SCAMT"];
			vo.CDTOT	= retObj["CDTOT"];
			vo.LTSF1	= retObj["LTSF1"];
			vo.LTSF2	= retObj["LTSF2"];
			vo.LTSF3	= retObj["LTSF3"];
			
			vo.CRDCD	= retObj["CRDCD"];	//신용카드 등
			//vo.GIROE	= retObj["GIROE"];	//학원비 지로납부
			vo.PUBTR	= retObj["PUBTR"];	//대중교통 이용분
			
			vo.CASHE	= retObj["CASHE"];	//현금영수증
			vo.DBTCD	= retObj["DBTCD"];	//직불카드
		
			vo.SMBFI	= retObj["SMBFI"];	//소기업 공제부금
			vo.PINVS	= retObj["PINVS"];	//투자조합출자(06)
			vo.TINVS	= retObj["TINVS"];	//투자조합출자(07)
			vo.NINVS	= retObj["NINVS"];	//2009년 1월이후 투자조합출자금
			
			//2013
			vo.INVST	= retObj["INVST"];	//투자조합출자(2013)
			vo.VINVS	= retObj["VINVS"];	//벤처투자(2013)						
			
			vo.COMST	= retObj["COMST"];	//우리사주
			vo.LTSF1	= retObj["LTSF1"];
			vo.LTSF2	= retObj["LTSF2"];
			vo.LTSF3	= retObj["LTSF3"];
			vo.INDIF	= retObj["INDIF"];	//고용유지임금삭감액
			//2012.12.28 j.t 추가
			vo.HSHLD	= retObj["HSHLD"];	//세대주여부
			vo.TRDUE	= retObj["TRDUE"];	//전통시장사용분
			
			////////////////////////////////////////////////////////////
			//2014
			vo.CDPRE	= retObj["CDPRE"];	
			vo.DBPRE	= retObj["DBPRE"];	
			vo.CRDEE	= retObj["CRDEE"];	
			vo.DBTHF	= retObj["DBTHF"];	
			
			vo.FINVT	= retObj["FINVT"];
			vo.FINVS	= retObj["FINVS"];
			vo.LTAIS	= retObj["LTAIS"];
			vo.IRLWL	= retObj["IRLWL"];
			vo.BETRG	= retObj["BETRG"];
			vo.LIMIT	= retObj["LIMIT"];
			return vo;
		}
		
		//세액감면 및 세액공제
		private function preseAmountReduction(retObj:Object):AmountReductionMoneyVO{
			var vo:AmountReductionMoneyVO = new AmountReductionMoneyVO();
			
			vo.POL01	= retObj["POL01"];
		 	vo.FTCHI	= retObj["FTCHI"];
			vo.ABPAY	= retObj["ABPAY"];
			vo.KORCR	= retObj["KORCR"];
			
			return vo;
		}
		
		//수정사항 메시지
		private function preseModifyMsg(arr:ArrayCollection):ArrayCollection{
			var returnArr:ArrayCollection = new ArrayCollection();
			for each(var reg:Object in arr){
				var vo:ModifyMsgVO = new ModifyMsgVO();
				vo.SEQNO	= int(reg["SEQNO"]).toString();
				vo.TEXT		= reg["TEXT"];
				returnArr.addItem(vo);
			}
			return returnArr;
		}
		
	}
}